package com.bytedance.common.a;

import android.content.Context;

import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class e implements f {
    private boolean a;
    private static ExecutorService b = new ThreadPoolExecutor(1, 3, 60, TimeUnit.SECONDS, new LinkedBlockingQueue());
    private final c c;
    private static e d = null;
    private final Context e;
    private final String f;
    private ConcurrentHashMap g;

    private e(Context arg5, String arg6, boolean arg7) {
        this.a = false;
        this.g = new ConcurrentHashMap();
        this.e = arg5;
        this.f = arg6;
        this.c = new c(arg5, arg7);
    }

    public static f a() {
        return d;
    }

    public static f a(Context arg3, String arg4, boolean arg5) {
        if (d == null) {
            Class v1 = e.class;
            synchronized (v1) {
                if (d == null) {
                    d = new e(arg3.getApplicationContext(), arg4, arg5);
                }
            }
        }

        return d;
    }

    public final List a(String host) {
        Object v0;
        Object v1 = null;
        if (!i.a(host) || (i.b(host)) || !i.a(this.e)) {
            label_40:
            v0 = v1;
        } else {
            v0 = this.c.a().get(host);
            if (v0 != null) {
                HttpDns.a("refresh host sync: " + host + " expired: " + ((a) v0).b());
            }

            if ((v0 == null || (((a) v0).b())) && !this.c.c.contains(host)) {
                this.b(host);
            }

            if (v0 == null) {
                v0 = v1;
            } else if (!((a) v0).b()) {
                v0 = v1;
            } else if (!((a) v0).b()) {
                v0 = v1;
            } else if (!this.a) {
                v0 = v1;
            }
        }

//        label_37:
        List v0_1 = v0 != null ? ((a) v0).b : ((List) v1);
        return v0_1;
    }

    private Future b(String arg5) {
        Future v0_1;
        try {
            v0_1 = b.submit(new h(arg5, this.f, this.c));
            this.c.c.add(arg5);
            this.g.put(arg5, v0_1);
        } catch (RejectedExecutionException v0) {
            v0_1 = null;
        }

        return v0_1;
    }

    public final void b() {
        HttpDns.b();
    }

    public final void c() {
        this.a = true;
    }

    public final void d() {
        c v0 = this.c;
        c.b(v0.a);
        v0.a.clear();
        c.b(v0.b);
        v0.b.clear();
        v0.c.clear();
    }
}

